package leetcode.每日一题;

import org.junit.Test;

import java.util.LinkedList;
import java.util.Stack;

/**
 * @author ：zsy
 * @date ：Created 2022/10/9 10:09 AM
 * @description：
 */
public class 括号的分数 {
    @Test
    public void test() {

    }

    class Solution {
        public int scoreOfParentheses(String s) {
            Stack<Integer> stack = new Stack<Integer>();
            stack.push(0);
            for (int i = 0; i < s.length(); i++) {
                char ch = s.charAt(i);
                if (ch == '(') {
                    stack.push(0);
                } else {
                    Integer v = stack.pop();
                    int top = stack.pop() + Math.max(v * 2, 1);
                    stack.push(top);
                }
            }
            return stack.peek();
        }
    }
}
